package com.sharemarking.wa.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sharemarking.wa.common.entity.Message;
import com.sharemarking.wa.platform.dto.message.MessageContentDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author dxy
 */
@Repository
public interface MessageMapper extends BaseMapper<Message> {
    @Select("SELECT id,title,body,create_date FROM sys_message WHERE id = #{id} AND member_id = #{memberId}  ")
    MessageContentDto getMessage(@Param("memberId") Integer memberId, @Param("id") Integer id);

    @Select("SELECT id,title,create_date,body FROM sys_message WHERE member_id = #{memberId} ORDER BY id DESC")
    List<MessageContentDto> getMessageList(Integer memberId);

    @Update("UPDATE sys_message SET is_push_sms = 1 WHERE member_id = #{memberId}")
    void updateState(Integer memberId);

    @Delete("DELETE from sys_message where member_id = #{memberId}")
    void deleteMessageList(Integer memberId);
}
